// 性别参数封装
export const sealGenderParam = (gender) => {
  return gender === 0 ? 'female' : 'male';
};

// 格式化日期
export const formatDate = (date) => {
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  return `${year}-${month}-${day}`;
};

// 格式化时间
export const formatTime = (date) => {
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  const hour = date.getHours();
  const minute = date.getMinutes();
  const second = date.getSeconds();

  return (
    [year, month, day].map(formatNumber).join('-') +
    ' ' +
    [hour, minute, second].map(formatNumber).join(':')
  );
};

// 格式化数字
const formatNumber = (n) => {
  n = n.toString();
  return n[1] ? n : '0' + n;
};

// 判断是否是有效的八电级测量数据
export const isValidEightMeasure = (scaleData) => {
  const validKeys = [
    'muscleRh',
    'muscleLh',
    'muscleRf',
    'muscleLf',
    'muscleT',
    'fatRh',
    'fatLh',
    'fatRf',
    'fatLf',
    'fatT',
  ];
  return validKeys.every((key) => scaleData[key]);
};